<?php


namespace app\admin\controller;


use app\common\lib\Auth;
use think\Request;

class System extends Base
{
    /**
     * get_type_config($type) 系统基本配置
     * @return mixed
     */
    public function index()
    {
        if(request()->isAjax()){
            $data = input('post.');
            try{
                $res = $this->_config->save(['value'=>$data['value']],['id'=>$data['id']]);
            }catch (\Exception $e){
                return show('200',$e->getMessage());
            }
            if(!$res) {
                return show('200','数据库错误','0');
            }
            return show('200','更新成功','1');
        }else {
            $this->assign([
                'base_config' => $this->config_type('1')
            ]);

            /*************************检测权限 开始***********************/
            $auth = new Auth();
            $request = Request::instance();
            if(!$auth->check($request->path(),$this->isLogin()->id)) {
                return $this->redirect('not_rule/index/index');
            }
            /*************************检测权限 结束***********************/
            return $this->fetch();
        }
    }

    public function tips()
    {
        if(request()->isAjax()){
            $data = input('post.');
            try{
                $res = $this->_config->save(['value'=>$data['value']],['id'=>$data['id']]);
            }catch (\Exception $e){
                return show('200',$e->getMessage());
            }
            if(!$res) {
                return show('200','数据库错误','0');
            }
            return show('200','更新成功','1');
        }else{
            $this->assign([
                'tips_config' => $this->config_type('2'),
                'error_config' => $this->config_type('3')
            ]);

            /*************************检测权限 开始***********************/
            $auth = new Auth();
            $request = Request::instance();
            if(!$auth->check($request->path(),$this->isLogin()->id)) {
                return $this->redirect('not_rule/index/index');
            }
            /*************************检测权限 结束***********************/
            return $this->fetch();
        }
    }
}